<?php session_start(); ?>
<?php include ("../inc/db_config.inc"); ?>
<?php
$g_title = "待审核评论";
$g_tab = "index";
$stab="comments_need";
$g_header = "";
$g_js = '<script type="text/javascript">
$(document).ready(function(){
    $("#checkall").change(function(){
        if($(this).attr("checked")==true){
            $("tr").find(":checkbox").attr("checked","checked");
        }else{
            $("tr").find(":checkbox").attr("checked","");
        } 
    })
    
    $("#delBtn").click(function(){
        var v=$("#comSelect").val();
        if(!v){
            alert("请先选择!");
            return false;
        }
        var arr=new Array();
        $("tr input:checked").each(function(i,item){
            arr.push($("tr input:checked").eq(i).val());
        })
       if(v==2){
       if(confirm("删除此评论?")){
        $.ajax({
            type:"POST",
            url:"comment_del.php",
            "data":{cid:arr,format:"json"},
            success:function(json){
                var obj=eval("("+json+")");
                var status=obj.Status;
                alert(obj.ReturnCode);
                if(status==1){
                    $("tr input:checked").each(function(i,item){

                            $(this).closest("tr").fadeOut("slow");

                        })
                    //window.location.reload();
                }
            },
            error:function(){
                alert("error");
            }
        })
        }
        }
        if(v==1){
            
            $.ajax({
            type:"POST",
            url:"comment_pass_action.php",
            "data":{cid:arr,format:"json"},
            success:function(json){
                var obj=eval("("+json+")");
                var status=obj.Status;
                alert(obj.ReturnCode);
                if(status==1){
                    window.location.reload();
                }
            },
            error:function(){
                alert("error");
            }
        })
        }
        
        if(v==3){
            $.ajax({
            type:"POST",
            url:"comment_rubbish_action.php",
            "data":{cid:arr,format:"json"},
            success:function(json){
                var obj=eval("("+json+")");
                var status=obj.Status;
                alert(obj.ReturnCode);
                if(status==1){
                    window.location.reload();
                }
            },
            error:function(){
                alert("error");
            }
        })
        }
    })
    
})
</script>';
?>
 <?php include ('header.php'); ?>
   <?php
function getPageInfo($sql, $ps, $currPage)
{
    global $beginNum, $begin, $end, $page, $totalpage;
    //分页开始
    $result = mysql_query($sql);
    //$all=mysql_fetch_array($rn);
    //$total=$all[0];//全部记录数目
    $total = mysql_num_rows($result);
    $pagesize = $ps;
    $page = $currPage;
    $totalpage = ceil($total / $pagesize);
    if ($page < 1) {
        $page = 1;
    }
    if ($page > $totalpage) {
        $page = $totalpage;
    }
    $begin = $page - 4;
    $end = $page + 5;
    if ($page < 5) {
        $begin = 1;
        $end = 10;
    }
    if ($page > $totalpage - 5) {
        $begin = $totalpage - 9;
        $end = $totalpage;
    }
    if ($begin < 1) {
        $begin = 1;
    }
    if ($end > $totalpage) {
        $end = $totalpage;
    }
    $beginNum = ($page - 1) * $pagesize;


    //分页结束
}
if (isset($_REQUEST['p']) && $_REQUEST['p'] != "") {
    $currPage = $_REQUEST['p'];
} else {
    $currPage = 1;
}
$pagesize = 10;
getPageInfo("select * from comment where isVal=0", $pagesize, $currPage);
?>
			<div class="crumb"></div>
			<div class="main">
				<div class="container r">
					<div class="conbox">
						<div class="cb_hd">
							<span class="cb_tl"></span>
							<span class="cb_tr"></span>
							<h2>待审核评论</h2>
						</div>
						<div class="cb_bd">
								<div class="article_act">
									<span class="ad_chk"><input id="checkall" type="checkbox"/> 选中项 <select id="comSelect"><option value="">请选择</option><option value="1">通过</option><option value="2">删除</option><option value="3">垃圾评论</option></select><button id="delBtn">确定</button></span>
									<span class="ad_show"></span>
									<?php if ($totalpage > 1) { ?><div class="pageinfo">
										<a href="?p=<?php echo $page - 1; ?>">上一页</a>
										<span><?php echo $page; ?></span>
										<a href="?p=<?php echo $page + 1; ?>">下一页</a>
									</div><?php } ?>
								</div>
								<table class="admin_table">
									<thead>
										<tr><th><th>内容</th><th>姓名</th><th>Email</th><th>日期</th><th width="60">操作</th></tr>
									</thead>
									<tbody>
                                    <?php
$result_cata = mysql_query("select * from comment where isVal=0 order by id desc limit $beginNum,$pagesize");
if (mysql_affected_rows() > 0) {
    while ($row_cata = mysql_fetch_array($result_cata)) {
?>
										<tr>
											<td><input type="checkbox" value="<?php echo $row_cata['id']; ?>"/></td>
											<td><?php echo $row_cata['cont']; ?></td>
											<td><?php echo $row_cata['name']; ?></td>
                                            <td><?php echo $row_cata['email']; ?></td>
                                            <td><?php echo $row_cata['post_date']; ?></td>
											<td><a href="comment_del.php?cid[]=<?php echo $row_cata['id']; ?>">删除</a></td>
										</tr>
                                        <?php }
} else { ?>
									<tr><td rowspan="6">暂无评论</td></tr>
                                        <?php } ?>
									</tbody>
								</table>
							
							
						</div>
						<div class="cb_ft"></div>
					</div>
					<?php if ($totalpage > 1) { ?>
					<div class="pageinfo">
                    <a href="?p=1">首页</a>
								<a href="?p=<?php echo $page - 1; ?>">上一页</a>
                                <?php
    for ($i = $begin; $i <= $end; $i++) {
        if ($i == $page) {
            echo "&nbsp;<span>" . $i . "</span>";
        } else {
            echo "&nbsp;<a href='?p=$i'>" . $i . "</a>";
        }
    }
?>
								<a href="?p=<?php echo $page + 1; ?>">下一页</a>
                                <a href="?p=<?php echo $totalpage; ?>">尾页</a>
							</div><?php } ?>
				</div>
				<?php include ('sidebar.php'); ?>
				<div class="c"></div>
			</div>
		</div>
	</div>
<?php include ('footer.php'); ?>
